﻿using Microsoft.Win32.SafeHandles;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace laohan.Common.USB.DeviceNotify
{
	internal class SafeNotifyHandle : SafeHandleZeroOrMinusOneIsInvalid
	{
		public SafeNotifyHandle()
			: base(ownsHandle: true)
		{
		}

		public SafeNotifyHandle(IntPtr pHandle)
			: base(ownsHandle: true)
		{
			SetHandle(pHandle);
		}

		protected override bool ReleaseHandle()
		{
			if (handle != IntPtr.Zero)
			{
				Win32API.UnregisterDeviceNotification(handle);
				handle = IntPtr.Zero;
			}
			return true;
		}
	}
}
